<template>
    <view>
        <!--标题和返回-->
		<cu-custom :bgColor="NavBarColor" isBack :backRouterName="backRouteName">
			<block slot="backText">返回</block>
			<block slot="content">预约客户</block>
		</cu-custom>
		 <!--表单区域-->
		<view>
			<form>
				<view class="cu-form-group">
					<view class="flex align-center">
					<view class="title">预约时间<text class="required-star">*</text></view>
					<my-date v-model="model.appointmentTime" placeholder="请选择预约时间"></my-date>
					</view>
				</view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title">预约结果</view>
                  <input placeholder="请输入预约结果" v-model="model.appointmentResults"/>
                </view>
              </view>
				<view class="padding">
					<button class="cu-btn block bg-blue margin-tb-sm lg" @click="onSubmit">
						<text v-if="loading" class="cuIcon-loading2 cuIconfont-spin"></text>提交
					</button>
				</view>
			</form>
		</view>
    </view>
</template>

<script>
    import myDate from '@/components/my-componets/my-date.vue'

    export default {
        name: "WorkOrderForm",
        components:{ myDate },
        props:{
          formData:{
              type:Object,
              default:()=>{},
              required:false
          }
        },
        data(){
            return {
				CustomBar: this.CustomBar,
				NavBarColor: this.NavBarColor,
				loading:false,
                model: {},
                backRouteName:'work',
                url: {
                  queryById: "/work/workOrder/queryById",
                  add: "/work/workOrder/reservation",
                  edit: "/work/workOrder/reservation",
                },
            }
        },
        created(){
             this.initFormData();
        },
		onLoad: function (option) {
			console.log("this.$Route.query",this.$Route.query);
			let query=this.$Route.query
			this.model = query;
		},
        methods:{
           initFormData(){
               if(this.formData){
                    let dataId = this.formData.dataId;
                    this.$http.get(this.url.queryById,{params:{id:dataId}}).then((res)=>{
                        if(res.data.success){
                            console.log("表单数据",res);
                            this.model = res.data.result;
                        }
                    })
                }
            },
            onSubmit() {
                let myForm = {...this.model};
                this.loading = true;
				let that = this;
				if(!myForm.appointmentTime || myForm.appointmentTime.length==0){
					this.$tip.alert('请选择预约时间');
					return false
				}
                let url = myForm.id?this.url.edit:this.url.add;
				that.$http.post(url,myForm).then(res=>{
				   console.log("res",res)
				   that.loading = false
				   if(res.data.success){
				   		that.$tip.alert(res.data.message);
						myForm.workOrderStatus=16;
						this.$Router.push({name:'detail', params:myForm});
				   		// that.$Router.push({name:that.backRouteName})
				   }else{
				   		that.$tip.alert(res.data.message);
				   }
				   
				}).catch(()=>{
					this.loading = false
				});
            }
        }
    }
</script>
<style>
	.required-star {
	    color: red;
	    margin-right: 5px;
	  }
</style>
